Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@ondrejmirtes
Copy link
Member

Nope, it's wrong. The IssetCheck should look at whether the certainty of a property is "maybe", not whether it has a native type or not.

@VincentLanglet
Copy link
Contributor Author

Nope, it's wrong. The IssetCheck should look at whether the certainty of a property is "maybe", not whether it has a native type or not.

I'm not fixing

if (isset($a->world)) { // shouldn't report any error

but the null check

if ($a->hello !== null) { // should report notIdentical.alwaysTrue 

There is nothing related to IssetCheck.

StrictComparisonOfDifferentTypesRule is calling

$this->richerScopeGetTypeHelper->getIdenticalResult($this->treatPhpDocTypesAsCertain ? $scope : $scope->doNotTreatPhpDocTypesAsCertain(), $node);

which does

if (
			(
				$expr->left instanceof Node\Expr\PropertyFetch
				|| $expr->left instanceof Node\Expr\StaticPropertyFetch
			)
			&& $rightType->isNull()->yes()
			&& !$scope->hasPropertyNativeType($expr->left)
		) {
			return new TypeResult(new BooleanType(), []);
		}

So when you check $object->foo !== null it will not considered as alwaysTrue when foo has no native type, because code might be

class MyObject 
{
     /** @var string */
     public $foo; // This is initialized with NULL since no native type is used.
}

@ondrejmirtes
Copy link
Member

I'm working on a better fix. Stay tuned 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not null Array shape property compared to null should report an error

2 participants